package com.koala.learn.threadlearn.test2;

import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

/**
 * @Description 一天只能三个线程进入
 * @Date 2022/3/22 20:44
 * @Created by koala
 */

@Slf4j
@AllArgsConstructor
public class Kitchen2 implements Runnable {

    // 限制厨房的厨师数量
    private int count;

    @SneakyThrows
    private void add() {

        if (count > 0) {
            log.info("厨师{}进入厨房 ", Thread.currentThread().getName());
            Thread.sleep(1000);
            log.info("厨师{}走出厨房", Thread.currentThread().getName());
        } else {
            log.info("厨师{} 进不来", Thread.currentThread().getName());
        }
    }

    @Override
    public void run() {
        add();
    }

}
